<template>
  <view class="search-tags">
    <view class="tags-item" v-for="(item,index) in taglist" :key="index"
     :class="{'active':searchTags.indexOf(index)!=-1}" @tap="itemClick(index)">
      {{item}}
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        taglist:['二手车','准新车','新车','黑标车'],
        searchTags:[]
      };
    },
    methods:{
      itemClick(index){
        const num=this.searchTags.indexOf(index)
        if(num!==-1){
          this.searchTags.splice(num,1)
        }else{
          this.searchTags.push(index)
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
.search-tags{
  height: 70upx;
  display: flex;
  justify-content: space-around;
  .tags-item{
    width: 20%;
    height: 50upx;
    border-radius: 3upx;
    font-size: 22upx;
    line-height: 50upx;
    text-align: center;
    background-color: #F5F7FA;
  }
  .active{
    color: #3c9cff;
    background-color: #ecf5ff;
  }
}
</style>
